#ifndef __TREE_DSTRUCT_H__
#define __TREE_DSTRUCT_H__

#include <stdint.h>

/* Maximum childs, depends on grammer */
#define MC			6

#define RED     "\x1b[31m"
#define GREEN   "\x1b[32m"
#define YELLOW  "\x1b[33m"
#define BLUE    "\x1b[34m"
#define CYAN    "\x1b[36m"
#define CLR     "\x1b[0m"


typedef enum symbolt {
	FUNCTION,
	LABEL_DEF,
	LABEL_REF,
	VARIABLE
} symbolt_t;

typedef enum tree_node_type {
	NONTERMINAL,
	TERMINAL_ID,
	TERMINAL_NUM,
	TERMINAL_TOK,
	TERMINAL_LEX,
	TERMINAL
} tree_node_type_t;

typedef enum op_node_type {
	NONE=1, /* Specifies Nodes which have no meaning in the code generating tree */
	OP_ADD,
	OP_MUL,
	OP_UN_NEG,
	OP_ARR,
	OP_ARR_ADDR,
	OP_NEQ,
	OP_LESS,
	OP_CALL,
	OP_CALL_VOID,
	OP_ARG,
	OP_ARG_NIL,
	TERM_ID,
	TERM_CONST,
	OPL_AND,
	OPL_NOT,
	OPL_OR,
	OP_EQ,
	OP_GRT
} op_node_type_t;

typedef enum reg {
	/* Argument Registers */
	RDI=0,
	RSI,
	RDX,
	RCX,
	R8,
	R9,
	/* Further Registers */
	RAX,
	R10,
	R11,
	ANY
} reg_t;

typedef struct symboll {
	symbolt_t type;
	reg_t reg;
	reg_t reg_id;
	char *name;
	long line;
	struct symboll *next;
} symboll_t;

typedef	symboll_t** (*id_syntax_cb_t)(symboll_t**, char*, long, symbolt_t);

typedef struct id_wrap {
	symbolt_t type;
	char *name;
	long line;
	id_syntax_cb_t syntax_cb;
} id_wrap_t;

typedef struct num_wrap {
	long val;
	long line;
} num_wrap_t;

typedef union tree_data {
	struct tree_node *child[MC];
	num_wrap_t num;
	id_wrap_t id;
	int token;
	char lexem;
} tree_data_t;

typedef struct tree_node {
	tree_data_t data;
	tree_node_type_t type;
	op_node_type_t op_type;
	uint8_t shortc;
	struct burm_state *state;
	char *name;
	struct tree_node *burm_child[2];
	//char *gen_name;
	long gen_val;
	//reg_t reg;
	long reg_id;
	symboll_t *symlist;
} tree_node_t, *NODEPTR_TYPE;

#endif
